package com.shse.sale.service.impl;

import com.shse.sale.dao.TrxDao;
import com.shse.sale.meta.Content;
import com.shse.sale.meta.Trx;
import com.shse.sale.service.TrxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import sun.util.calendar.CalendarUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by shse on 4/5/2016.
 */
@Service("trxService")
public class TrxServiceImpl implements TrxService {

    @Autowired
    private TrxDao trxDao;

    @Override
    public Trx getTrxByContent(int contentId) {
        return trxDao.getTrxByContent(contentId);
    }

    @Override
    public void addTrx(Content content, int personId) {
        Trx trx = new Trx();
        trx.setContentId(content.getId());
        trx.setPersonId(personId);
        trx.setPrice(content.getPrice());

//        SimpleDateFormat df = new  SimpleDateFormat("yyyyMMddHHmm");
//        String s= df.format(new Date());
//        Long buyTime = Long.parseLong(s);
        Long buyTime = (new Date()).getTime();
        trx.setTime(buyTime);

        trxDao.addTrx(trx);
    }
}
